<template>
  <div class="home">
    <div class="container">
      <transition :name="transitionName">
        <router-view class="view"></router-view>
      </transition>
    </div>
    <van-tabbar v-model="active"
                @change="onChange">
      <van-tabbar-item icon="home-o"
                       to="/home">首页</van-tabbar-item>
      <van-tabbar-item icon="search"
                       to="/search">查询</van-tabbar-item>
      <van-tabbar-item icon="friends-o"
                       to="/friend">好友</van-tabbar-item>
      <van-tabbar-item icon="setting-o"
                       to="/setting">设置</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
// @ is an alias to /src

export default {
  name: 'Home',
  data () {
    return {
      active: 0,
      transitionName: ''
    }
  },
  watch: {
    $route (to, from) {
      if (from.path == '/') return
      to.meta.index > from.meta.index ? this.transitionName = 'slide-left' : this.transitionName = 'slide-right'
      console.log(this.transitionName)
    }
  },
  methods: {
    onChange (...args) {
    }
  }
}
</script>
<style lang="less" scoped>
.home {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.container {
  flex: 1;
  overflow: auto;
}
.van-tabbar {
  position: relative;
}
.view {
  width: 100%;
  // position: absolute;
}
.slide-right-enter-active,
.slide-right-leave-active,
.slide-left-enter-active,
.slide-left-leave-active {
  will-change: transform;
  transition: all 1s;
  position: absolute;
}
.slide-right-enter {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
.slide-right-leave-active {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-enter {
  opacity: 0;
  transform: translate3d(100%, 0, 0);
}
.slide-left-leave-active {
  opacity: 0;
  transform: translate3d(-100%, 0, 0);
}
</style>
